package com.newdream.eurekaclient.controller;

import com.newdream.eurekaclient.model.Student;
import com.newdream.eurekaclient.model.User;
import com.newdream.eurekaclient.service.StudentService;
import com.newdream.eurekaclient.service.UserService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Random;

/**
 * @ author: sanglei
 * @ date: 2019-04-19 14:42
 * @ description:
 */
@Api(value = "test",produces = MediaType.APPLICATION_JSON_VALUE)
@RestController
@RefreshScope
public class TestController {
    private final Random random = new Random();
    @Value("${aa}")
    private String aa;
    @Autowired
    private UserService userService;
    @Autowired
    private StudentService studentService;
    @GetMapping("test")
    public Object test(){
        User user = new User();
        user.setName(aa);
        return user;
    }
    @GetMapping("get")
    public User selectUser(@RequestParam("id") Integer id){
        int sleepTime = random.nextInt(200);
        try {
            Thread.sleep(sleepTime);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("这是eureka-client1返回的数据");
        User user = userService.getUserById(id);
        return user;
    }
    @GetMapping("dev")
    public Object dev(@RequestParam("id") Integer id){
        Student student = studentService.get(id);
        return student;
    }
}
